import { ProFormOptions } from '@/components/pro-form/type'
import { BudgetModel } from '@/api/model/budget-model'
import { Ref } from 'vue'
import { optionsType } from '~/types/form'

type Props = {
  handleType: Ref<'add' | 'edit' | 'check'>
}

export const useBudgetProForm = ({ handleType }: Props) => {
  const [budgetForm, resetBudgetForm] = useProRef<Partial<BudgetModel>>({})

  const budgetFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'budgetName',
        label: '预算名称'
      },
      {
        formType: 'input',
        key: 'budgetCode',
        label: '预算编码',
        disabled: true
      },
      {
        formType: 'inputNumber',
        key: 'budgetAmount',
        min: 0,
        precision: 2,
        label: '预算金额'
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'select',
        key: 'receiveType',
        label: '申请状态',
        options: useDictData('STATUS').value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveReason',
        label: '申请原因'
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        noRule: true
      },
      {
        formType: 'textarea',
        key: 'reason',
        label: '批复',
        gridItem: {
          span: 2
        },
        noRule: true,
        disabled: true
      }
    ] as optionsType
    if (handleType.value === 'add') {
      return useSetOptions(list.filter((item) => !item.disabled))
    } else {
      return useSetOptions(list)
    }
  })

  return {
    budgetForm,
    budgetFormOptions,
    resetBudgetForm
  }
}
